<table data-options="fit:true" id="subject_manager"></table>

<script>
	$(function(){
		$.post("../testServlet",{op:"getTest"},function(data){
			var sltObj=$("#subject_tid");//获取下拉对象
			var opt;
			$.each(data.tidInfo,function(index,item){
				opt="<option value='"+item.tid+"'>"+item.tname+"</option>";
				sltObj.append($(opt));
			});
		},"json");
		var datagrid; 
		datagrid=$('#subject_manager').datagrid({   
		    url:'../subjectServlet',
		    queryParams:{op:"getAllSubject"},
		    loadMsg:'数据加载中...',
		    pagination:true,
		    fitColumns:true,
		    rownumbers:true,
		    striped:true,
		    pageNumber:1,
		    sortOrder:'asc',
		    remoteSort:false,//定义是否通过远程服务器对数据排序。
		    sortName:'sid',
		    columns:[[
		    	{field:'sids',title:'',checkbox:true,width:100,align:'center'},   
		        {field:'sid',title:'编号',width:100,align:'center'},   
		        {field:'tid',title:'关联测试',width:100,align:'center'},
		        {field:'qcontent',title:'题目内容',width:200,align:'center'},
		        {field:'sscore',title:'题目得分',width:200,align:'center'}
		    ]],
		    toolbar: [{
		    	text:'添加',
				iconCls: 'icon-add',
				handler: function(){
					$("#add_subject").dialog("open");
				}
			},'-',{
				text:'删除',
				iconCls: 'icon-remove',
				handler: function(){
						
				}
			}]   
		});
  
	});
</script>

<div id="add_subject" class="easyui-dialog" title="添加题目" style="width:800px;height:300px"
	data-options="iconCls:'icon-add',resizeble:true,modal:true,closed:true">
	<br /><br />
	<form action="" style="float:left;padding-left:20px" id="subjectInfo" name="subjectInfo" method="post">
		<p><label>关联测试:</label>
			<select id="subject_tid" name="tid"></select>
		</p>
		<p><label style="vertical-align: top">题目内容:</label>
			<textarea cols="100" rows="3" id="subject_qcontent" name="qcontent"></textarea>
		</p>
		<p><label style="vertical-align: top">题目选项:</label>
			<textarea cols="100" rows="3" id="subject_scontent" name="scontent"></textarea>
		</p>
		<p><label>题目得分:</label><input type="text" id="subject_sscore" name="sscore" style="width:200px;"></p>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="addSubject()" style="margin-left:60px;">添加</a>			
	</form>
</div>

<script>
	function addSubject(){
		var tid=$("#subject_tid").val();
		var qcontent=$("#subject_qcontent").val();
		var scontent=$("#subject_scontent").val();
		var sscore=$("#subject_sscore").val();
		console.info(tid+"\t"+qcontent+"\t"+scontent+"\t");
		$.post("../subjectServlet",{op:"addSubject",tid:tid,qcontent:qcontent,scontent:scontent,sscore:sscore},function(data){
			data=parseInt($.trim(data));
				if(data==1){
					$.messager.show({
						title:'成功提示',
						msg:'测试添加成功...',
						timeout:3000,
						showType:'slide'
					});
					$('#add_subject').dialog("close");
					$('#subject_manager').datagrid("reload");
					$("#subjectInfo")[0].reset();
				}else{
					$.messager.alert('错误提示','测试添加失败,请稍后重试...','error');
				}
		});
	}
</script>